﻿using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Windows;
using System.Reflection;

namespace FSNCleaner
{
    /// <summary>
    /// Interaction logic for App.xaml
    /// </summary>
    public partial class App : Application
    {
        protected override void OnStartup(StartupEventArgs e)
        {
            AppDomain.CurrentDomain.AssemblyResolve += (sender, args) =>
            {
                String resourceName = new AssemblyName(Assembly.GetExecutingAssembly().FullName).Name
                    + "." + new AssemblyName(args.Name).Name + ".dll";
                using (var stream = Assembly.GetExecutingAssembly().GetManifestResourceStream(resourceName))
                {
                    Byte[] assemblyData = new Byte[stream.Length];
                    stream.Read(assemblyData, 0, assemblyData.Length);
                    return Assembly.Load(assemblyData);
                }
            };

            base.OnStartup(e);

            var vm = this.FindResource("MyViewModel") as ViewModel;

            if (e.Args.Length > 0)
            {
                switch (e.Args[0])
                {
                    case "/CleanDirectoryAll":
                        vm.ScriptDirectoryCommand.Execute(null);
                        break;
                }
            }
        }
    }
}
